﻿var myClick = false;
function actionActivity(aid,item,TemplateID) {
    $.ajax({
        type: "get",
        url: '/app/PreView/GetAwards',
        data: { "aId": aid },
        async: false,
        success: function (data) {
            var Denomination = data.Denomination;
            if (data.Denomination == -1) { //没有中到奖品
                // 跳转到没中奖页面
                $(item).children("img:nth-child(2)").attr("src", "/app/Content/Images/GoldEggs/hit.png").css("display", "block");
                $("#small").css("animation-play-state", "paused");
                $("span").css("animation-play-state", "paused");
                setTimeout(function () {
                    $(item).children("img:nth-child(1)").attr("src", "/app/Content/Images/GoldEggs/egg2.png");

                    setTimeout(function () {
                        GetError(TemplateID);
                    }, 1000)
                }, 300);
            }
            else {  //中到奖品了
                if (data.type == 3) { //流量
                    $(item).children("img:nth-child(2)").attr("src", "/app/Content/Images/GoldEggs/hit.png").css("display", "block");
                    $("#small").css("animation-play-state", "paused");
                    $("span").css("animation-play-state", "paused");
                    setTimeout(function () {
                        $(item).children("img:nth-child(1)").attr("src", "/app/Content/Images/GoldEggs/egg2.png");

                        setTimeout(function () {
                            $('#awardImg').attr("src", data.AwardsIosUrl)
                            $(".bg-con .small-bg p:nth-child(2) span").text('价值' + data.Denomination + '元流量券').css({ 'width': 'auto', 'padding': '0 5px', 'color': '#E23524' });
                            $(".bg-con .small-bg p:nth-child(3) span").text(data.Name);
                            $('.bg-con .add').attr('href', 'Verification?awId=' + data.Id + '&Aid=' + data.ActivityId + '&Denomination=' + data.Denomination);
                        }, 1000)
                    }, 300);
                    myClick = true; //一次抽奖完成后，设置click为true，可继续抽奖
                    actionActivity(aid, item);
                    return false;
                }
                else if (data.type == 2) {//优惠券
                }
                else { //红包
                    if (myClick) { //click控制一次抽奖过程中不能重复点击抽奖按钮，后面的点击不响应
                        return false;
                    } else {
                        $(item).children("img:nth-child(2)").attr("src", "/app/Content/Images/GoldEggs/hit.png").css("display", "block");
                        $("#small").css("animation-play-state", "paused");
                        $("span").css("animation-play-state", "paused");
                        setTimeout(function () {
                            $(item).children("img:nth-child(1)").attr("src", "/app/Content/Images/GoldEggs/egg2.png");

                            setTimeout(function () {
                                //$('#awardImg').attr("src", data.AwardsIosUrl)
                                $(".bg-con .small-bg p:nth-child(2) span").text(data.Denomination + '元').css({ 'width': 'auto', 'padding': '0 10px', 'color': '#E23524' });
                                $(".bg-con .small-bg p:nth-child(3) span").text(data.Name);
                                $('.bg-con .add').attr('href', 'Verification?awId=' + data.Id + '&Aid=' + data.ActivityId + '&Denomination=' + data.Denomination);
                                $('#bg-con>div:nth-child(2)').addClass("receive");
                                $('#bg-con').css('display', 'flex');
                            }, 1000)
                        }, 300);
                        myClick = true; //一次抽奖完成后，设置click为true，可继续抽奖
                        actionActivity(aid, item,TemplateID);
                        return false;
                    }
                }
            }
        }
    });
}